import { SelectRendererOptions, createCellRender } from '@mxpio/components';

import XEUtils from 'xe-utils';
import type { VxeGlobalRendererHandles, VxeGlobalRendererOptions } from '@mxpio/types';

function getSelectCellValue(
  renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions,
  params: VxeGlobalRendererHandles.RenderTableCellParams,
) {
  // const { props = {} } = renderOpts;
  const { row, column } = params;
  // todo 后续拓展字典选择翻译
  // const { dictCode } = props;
  // const cellValue = XEUtils.get(row, column.field as string);
  const textMap = XEUtils.get(row, 'textMap');
  return textMap && textMap[`${column.field}$DICT_TEXT_`]
    ? textMap[`${column.field}$DICT_TEXT_`]
    : row[column.field];
}

export default {
  renderTableEdit: SelectRendererOptions.renderTableEdit,
  renderFormItemContent: SelectRendererOptions.renderFormItemContent,
  renderTableCell: createCellRender(getSelectCellValue),
} as VxeGlobalRendererOptions;

// export default SelectRendererOptions;
